package com.summer.safe.config.datasource;

import com.alibaba.druid.filter.config.ConfigTools;
import com.alibaba.druid.pool.DruidDataSource;

/**
 *
 * 用来解密配置中的密文
 *
 */
@SuppressWarnings("all")
public class DecryptDruidSource extends DruidDataSource {
	/**
	 * 解密数据库名称
	 * @param username
	 */
	@Override
	public void setUsername(String username) {
		try {
			username = ConfigTools.decrypt(username);
		} catch (Exception e) {
			e.printStackTrace();
		}
		super.setUsername(username);
	}


	/**
	 * 解密数据库密码
	 * @param password
	 */
	@Override
	public void setPassword(String password) {
		try {
			password = ConfigTools.decrypt(password);
		} catch (Exception e) {
			e.printStackTrace();
		}
		super.setPassword(password);
	}
	
	public static void main(String[] args) {
		String userName1 = "123456";
		String userName2 = "oHzvbVOkbxq/S0e9AU+AsS+APRd67n8dhM/CPrpa86WdRggOpD+2jVgBLdM2zleI6PsBSGS2frVrmw/Y1vCfqw==";
		try {
			String userName_encrypt = ConfigTools.encrypt(userName1);//加密
			String userName_decrypt = ConfigTools.decrypt(userName2);//解密
			System.err.println(userName_encrypt);
			System.err.println(userName_decrypt);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


	}
}